﻿$(function () {
    var str = window.location.href;
    if (str.indexOf("www.sparkletour.com") > 0 && str.indexOf("www.sparkletour.com/?m") == -1) {
        var sUserAgent = navigator.userAgent.toLowerCase();
        var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
        var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
        var bIsAndroid = sUserAgent.match(/android/i) == "android";
        var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
        var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
        var bIsMidp = sUserAgent.match(/midp/i) == "midp";
        var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
        var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
        var isVisitPCSite = document.cookie ? document.cookie.indexOf("visitpc=true") > 0 : false;
        if ((bIsCE || bIsMidp || bIsUc7 || bIsUc || bIsIphoneOs || bIsAndroid || bIsWM) && !isVisitPCSite) {
            window.location.href = "http://m.sparkletour.com/";
        }
    }
    $("#hcpydxx").on("click", function () {
        if ($("#dProductinfo").is(":hidden")) {
            $("#dProductinfo").show();
        }
        else {
            $("#dProductinfo").hide()
        }
    });
    $('.logined').hover(function () {
        $(this).find('.loginBtnNav').show();
    }, function () {
        $(this).find('.loginBtnNav').hide();
    });
    var searchBox;
    /*
    $('#tigong label').click(function () {
        $('#tigong label').removeClass('checked');
        $(this).addClass('checked');
    });
    */
    $("input[name=isprovtraveler]").on("click", function () {
        if (this.value == "true") {
            $(".nonrealtime-traveler").slideDown();
        }
        else {
            $(".nonrealtime-traveler").slideUp();
        }
    });
    $('.selectck label').click(function () {
        $(this).parents(".selectck").find("label").removeClass('checked');
        $(this).addClass('checked');
    });
    $(".travelereditor .selectck label, .TouristInfo .selectck label").on("click", function () {
        var container = $(this).parents(".input-box");
        var pnlClass = $(this).attr("relPanel");
        container.find(".completeInfo").hide();
        container.find("." + pnlClass).show();
        if (pnlClass == "provideNow") {
            container.find("input[name='hidInputCustomer']").val("true");
        }
        else {
            container.find("input[name='hidInputCustomer']").val("false");
        }

    });

    $(".InvoiceInfo #tigong3 label").on("click", function () {
        var container = $(this).parents(".input-box");
        var pnlClass = $(this).attr("relPanel");
        if (pnlClass == "completeInfo") {
            container.find("input[name='hidNeedInvoice']").val("true");
            container.find("." + pnlClass).show();
        }
        else {
            container.find("input[name='hidInputCustomer']").val("false");
            container.find(".completeInfo").hide();
        }

    });

    $(".InvoiceInfo #tigong4 label").on("click", function () {
        var container = $(this).parents(".completeInfo-content");
        var pnlClass = $(this).attr("relPanel");
        $(".selfpick, .deliver").hide();
        container.find("." + pnlClass).show();
        if (pnlClass == "deliver") {
            container.find("input[name='hidIsDelivery']").val("true");
        }
        else {
            container.find("input[name='hidIsDelivery']").val("false");
        }

    });

    searchBox = new sparkleAutoSearch({ target: "searchByDestination", source: ProductLables });
    $("#btnHeadSearch").on("click", function () {
        var labelId = searchBox.value;
        if (labelId) {
            prodListUrl = prodListUrl.replace(/\/$/, "");
            var navUrl = prodListUrl + "/" + labelId;
            navUrl += "?fromSearch=1";
            var start = $("#txtStartDate").val();
            var end = $("#txtEndDate").val();
            if (start) {
                navUrl = navUrl + "&startDate=" + start.replace("年", "-").replace("月", "-").replace("日", "");
            }
            if (end) {
                navUrl = navUrl + "&endDate=" + end.replace("年", "-").replace("月", "-").replace("日", "");
            }
            
            window.location.href = navUrl;
        }
    });
    $("*[orinUrl]").each(function () {
        $this = $(this);
        var imgUrl = $this.attr("orinUrl");
        if (imgUrl) {
            $this.attr("src", imgUrl);
        }
    });
    $("*[bgImage]").each(function () {
        $this = $(this);
        var bgImg = $this.attr("bgImage");
        if (bgImg) {
            $this.css("background-image", "url('" + bgImg + "')");
        }
    });
    $("#browser .close").on("click", function () {
        $("#browser").hide();
    });

    $('#tab ul li').click(function () {
        $('#tab ul li').removeClass('active');
        $(this).addClass('active');
        $('#tab .tabal-content').removeClass('active');
        $('#tab .tabal-content').eq($(this).index()).addClass('active');
    });
    $('.clauseYes label').click(function () {
        if ($(this).find('input')[0].checked) {
            $(this).addClass('checked');
            $(".warningContract").hide();
        } else {
            $(this).removeClass('checked');
        }
    });
    $('.datePickerFree').datepicker({
        format: 'yyyy-mm-dd',
        language: 'zh-CN',
        weekStart: 0,
        orientation: 'top left',
        autoclose:true
    });
    $(".guestpicker").on("change", function () {
        if (this.checked) {
            fillGuestField(this);
        }
        else {
            emptyGuestField(this);
        }

        
    });
});
function emptyGuestField(ctrlGuest)
{
    var objGuest;
    var memberId = ctrlGuest.value;
    //var index = $(".guestpicker:checked").length - 1;
    var $container = $(".custContainer[hasGuest="+memberId+"]").eq(0);
    $container.attr("hasGuest", "false");
    //$container.find("label[relPanel=provideNow]").click();
    $container.find(".completeInfo").hide();
    $container.find(".provideLater").show();
    $container.find(".selectck label:eq(0)").removeClass("checked");
    $container.find(".selectck label:eq(1)").addClass("checked");
    $container.find("input[name='hidInputCustomer']").val("false");
    $container.find("div.birthday").hide();

    $container.find("input[type=text],input[type=hidden]").val("");
    $container.find("input[name=rdoSex2]:eq(0)").prop("checked", true);
    $container.find("select option:eq(0)").prop("selected", true);
    $container.find("small.must").hide();
}
function fillGuestField(ctrlGuest)
{
    var objGuest;
    var memberId = ctrlGuest.value;
    //var index = $(".guestpicker:checked").length-1;
    var $container = $(".custContainer[hasGuest=false]").eq(0);
    if ($container.length == 0)
    {
        ctrlGuest.checked = false;
        alert("抱歉，已经再不能添加联系人了。");
        return false;
    }
    $container.attr("hasGuest", memberId);
    for (var i = 0; i < globalGuests.length; i++)
    {
        if (globalGuests[i].MemberGuestId == memberId)
        {
            objGuest = globalGuests[i];
            break;
        }
    }
    //$container.find("label[relPanel=provideNow]").click();
    $container.find(".completeInfo").hide();
    $container.find(".provideNow").show();
    $container.find(".selectck label:eq(0)").addClass("checked");
    $container.find(".selectck label:eq(1)").removeClass("checked");
    $container.find("input[name='hidInputCustomer']").val("true");
    if (objGuest.VoucherType != 1) {
        $container.find("div.birthday").show();
    }
    
    $container.find("input[name=hidMemberGuestID]").val(objGuest.MemberGuestId);
    $container.find("input[name=custName]").val(objGuest.Name);
    $container.find("input[id^=spEnglishNameShow]").val(objGuest.EnglishFirstName + objGuest.EnglishLastName);
    $container.find("input[name=pinyinFirstName]").val(objGuest.EnglishFirstName);
    $container.find("input[name=pinyinLastName]").val(objGuest.EnglishLastName);
    $container.find("input[name=custBirthday]").val(objGuest.BirthDay);
    $container.find("input[name=rdoSex2][value=" + objGuest.Sex + "]").prop("checked",true);
    $container.find("select[name=custCertifiType]").val(objGuest.VoucherType);
    $container.find("input[name=custCertificate]").val(objGuest.VoucherNo);
    $container.find("input[name=custCell]").val(objGuest.Mobile);
    if (objGuest.TravelType) {
        $container.find("select[name=custPassportType]").val(objGuest.TravelType);
    }
    $container.find("input[name=custPassport]").val(objGuest.TravelNo);
    $container.find("input[name=custPassportExpire]").val(objGuest.ValidDate);
    $container.find("input[name=custPassportCityName]").val(objGuest.IssuePlaceText);
    $container.find("input[name=custPassportCity]").val(objGuest.IssuePlace);
}
function locateTab(obj) {
    if (obj.href.indexOf("costExplanation") > -1 || obj.href.indexOf("bookingNotice") > -1) {
        window.location = "#bookingNotice";
        window.location = "#costExplanation";
    }
    else {
        window.location.href = obj.href;
    }
    window.setTimeout(function () { window.scrollBy(-1, -1); }, 70);
}
function checkEmail()
{
    var reg = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    if (reg.test($("#contactEmail").val())) {
        $(".msgemail").hide();
        return true;
    }
    else {
        $(".msgemail").show();
        return false;
    }
}
function checkCell()
{
    var reg = /^((\+86)|(86))?(1)\d{10}$/;
    if (reg.test($("#contactCell").val())) {
        $(".msgcell").hide();
        return true;
    }
    else {
        $(".msgcell").show();
        return false;
    }
}

function checkCName(obj) {
    var sender = $(obj);
    var pattern = /^[\u0391-\uFFE5]+$/;
    var re = /^[a-zA-Z\d\u4e00-\u9fa5]+$/;
    if ((!pattern.test(sender.val())) || (!re.test(sender.val()))) {
        /*
        $("#spTravellerName" + x).html("请输入中文姓名");
        $("#divTravellerName" + x).addClass("ui-form-item-error");
        $("#divEnglishName" + x).addClass("hidden");
        */
        sender.parent().find(".msgname").show();
        return false;
        
    }
    else if (sender.val().length > 10 || sender.val().length <= 1) {
       /*
        $("#spTravellerName" + x).html("请正确输入中文姓名");
        $("#divTravellerName" + x).addClass("ui-form-item-error");
        $("#divEnglishName" + x).addClass("hidden");
       */
        sender.parent().find(".msgname").show();
        return false;
    }
    sender.parent().find(".msgname").hide();
    return true;
   
}

function showBirthField(obj)
{
    var type = $(obj).val();
    if (type == 1) {
        $(obj).parents(".input-box").siblings(".birthday").hide();
    }
    else {
        $(obj).parents(".input-box").siblings(".birthday").show();
    }
    

}
//证件号码
function checkcardno(obj) {
    var sender = $(obj);
    var Type = sender.parents(".input-box").find("select[name='custCertifiType']");
    var container = sender.parents(".custContainer");
    
    //$("#divcardnoShow" + x).addClass("hidden");
    var reg = /[\s]/g;
    
    
        /*
        removeDivClass("cardno" + x);
        if (!GLOBAL.Lang.isNullorEmpty(sender.val()) || sender.val() == sender.attr("def")) {
            if (checkType == 2) {
                $("#spcardno" + x).html("请填写" + $("#selIDCardType" + x + " option:selected").html().replace(reg, "") + "号码");
                $("#divcardno" + x).addClass("ui-form-item-error");
                return false;
            }
            else {
                blurShow(sender);
            }   
        }
        */
            if (Type.val() == 1) {//身份证自动带出
                if (sender.val().length != 18 || parseInt(sender.val().substring(6, 10), 10) < 1930 ||
                    parseInt(sender.val().substring(6, 10), 10) > 2020 || parseInt(sender.val().substring(10, 12), 10) > 12 || parseInt(sender.val().substring(10, 12), 10) < 1
                     || parseInt(sender.val().substring(12, 14), 10) < 1 || parseInt(sender.val().substring(12, 14), 10) > 31 || !checkIdCard(sender.val())) {
                    /*
                    $("#spcardno" + x).html($("#selIDCardType" + x + " option:selected").html().replace(reg, "") + "号码格式错误");
                    $("#divcardno" + x).addClass("ui-form-item-error");
                    */
                    container.find(".msgidcard").show();
                    return false;
                }
                else {
                    container.find("input[name='custBirthday']").val(sender.val().substring(6, 10) + "-" + sender.val().substring(10, 12) + "-" + sender.val().substring(12, 14));
                    container.find(".msgidcard").hide();
                }
                
                var tempSex;
                if (sender.val().substring(16, 17) % 2 == 0) {
                    
                    //$("#hidsex" + x).val("2");
                    tempSex=2;
                }
                else {
                    //$("#hidsex" + x).val("1");
                    tempSex=1;
                }
                sender.parents(".custContainer").find("input[name^=rdoSex]").each(function () {
                    if ($(this).val() == tempSex)
                    { 
                        this.checked = true;
                    }
                    });
                
                //$("input[name='iptsex" + x + "']:eq(" + (sender.val().substring(16, 17) - 1) + ")").attr("checked", 'checked');
            }
            else if (sender.val().length > 20) {
                /*
                $("#spcardno" + x).html("证件号长度需小于20");
                $("#divcardno" + x).addClass("ui-form-item-error");
                */
                container.find(".msgidcard").show();
                return false;
            }
            else {
                container.find(".msgidcard").hide();
            }
    
    /*
    if (!GLOBAL.Lang.isNullorEmpty(sender.val()) || sender.val() == sender.attr("def")) {
        return false;
    }
    $("#divcardno" + x).addClass("ui-form-item-finish");
    */
    return true;
}
//检查身份证号码
function checkIdCard(idcard) {
    var area = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" }

    var idcard, Y, JYM, JYM_X;
    var S, M, M_X;
    var idcard_array = new Array();
    idcard_array = idcard.split("");
    /*地区检验*/
    if (area[parseInt(idcard.substr(0, 2))] == null) {
        return false;
    }
    if (parseInt(idcard.substr(6, 4)) % 4 == 0 || (parseInt(idcard.substr(6, 4)) % 100 == 0 && parseInt(idcard.substr(6, 4)) % 4 == 0)) {
        ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/; //闰年出生日期的合法性正则表达式  
    }
    else {
        ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/; //平年出生日期的合法性正则表达式  
    }
    if (ereg.test(idcard)) {//测试出生日期的合法性  
        //计算校验位  
        S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
						+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
						+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
						+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
						+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
						+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
						+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
						+ parseInt(idcard_array[7]) * 1
						+ parseInt(idcard_array[8]) * 6
						+ parseInt(idcard_array[9]) * 3;
        Y = S % 11;
        M = "F";
        JYM = "10x98765432";
        JYM_X = "10X98765432";
        M = JYM.substr(Y, 1); /*判断校验位*/
        M_X = JYM_X.substr(Y, 1); /*判断校验位*/

        if (M == idcard_array[17] || M_X == idcard_array[17]) {
            return true; /*检测ID的校验位false;*/
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
}
function checkBirth(obj)
{
    if (!$(obj).val()) {
        $(obj).siblings(".msgbirthday").show();
        return false;
    }
    else {
        $(obj).siblings(".msgbirthday").hide();
        return true;
    }
}
function checkPassport(obj)
{
    if (!$(obj).val()) {
        $(obj).siblings(".msgpassport").show();
        return false;
    }
    else {
        $(obj).siblings(".msgpassport").hide();
        return true;
    }
}
function checkValidTo(obj)
{
    if (!$(obj).val()) {
        $(obj).siblings(".msgvalidto").show();
        return false;
    }
    else {
        $(obj).siblings(".msgvalidto").hide();
        return true;
    }
}
function checkIssuePlace(obj)
{
    if (!$(obj).val()) {
        $(obj).siblings(".msgissueplace").show();
        return false;
    }
    else {
        $(obj).siblings(".msgissueplace").hide();
        return true;
    }
}
function checkIsInvoice(obj) {
    if (!$(obj).val()) {
        $(obj).siblings(".fpttmgs").show();
        return false;
    }
    else {
        $(obj).siblings(".fpttmgs").hide();
        return true;
    }
}
function checkIsinvoiceType(obj) {
    if ($(obj).val() == '0') {
        $(obj).siblings(".fplbmgs").show();
        return false;
    }
    else {
        $(obj).siblings(".fplbmgs").hide();
        return true;
    }
}
function checkIsInaddress(obj) {
    if (!$(obj).val()) {
        $(obj).siblings(".inaddressmgs").show();
        return false;
    }
    else {
        $(obj).siblings(".inaddressmgs").hide();
        return true;
    } checkIsInaddress
}
function checkIsIncode(obj) {
    if (!$(obj).val()) {
        $(obj).siblings(".incodemgs").show();
        return false;
    }
    else {
        $(obj).siblings(".incodemgs").hide();
        return true;
    } checkIsInaddress
}
function checkIsInreceiver(obj) {
    if (!$(obj).val()) {
        $(obj).siblings(".inreceivermgs").show();
        return false;
    }
    else {
        $(obj).siblings(".inreceivermgs").hide();
        return true;
    } checkIsInaddress
}
function checkIsInphone(obj) {
    if (!$(obj).val()) {
        $(obj).siblings(".inphonemgs").show();
        return false;
    }
    else {
        $(obj).siblings(".inphonemgs").hide();
        return true;
    } checkIsInaddress
}
function validateBookingRoom(frm)
{
    var resu = false;
    window.doNavOrder = true;
    var cusAdultNumber = parseFloat($("#bcustomiseAdultQuantity").val());
    var cusChildNumber = parseFloat($("#bcustomiseChildrenNumber").val());
    var roomNumber = parseFloat($("#bcustomiseRoomQuantity").val());
    var cusNumber = cusAdultNumber + cusChildNumber;
    if (cusNumber / roomNumber > 2) {
        if (!confirm("根据酒店要求，大于等于3人选择入住一间酒店会产生费用的增加，预订成功后，待销售人员与您电话确认。")) {
            return false;
        }
    }
    $.ajax({
        async: false,
        url: isLoginUrl,
        type: "post",
        success: function (resp) {
            resu = resp.result;
        }
    });
    if (resu) {
        showLoader($(frm).find("#btnNextStep"));
        return true;
    }
    else {
        $('#modalBookNow').modal('hide');
        modalMyYaoyueShow();
        return false;
    }
}
function validateNonRealTimeSubmit() {
    flag = true;
    if (!checkEmail()) {
        $("#contactEmail").focus();
        flag = false;
    }
    if (!checkCell()) {
        $("#contactCell").focus();
        flag = false;
    }
    if (!checkCName(document.getElementById("contactName"))) {
        document.getElementById("contactName").focus();
        flag = false;
    }
    $("input[name='custName']:visible").each(function () {
        if (!checkCName(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custCertificate']:visible").each(function () {
        if (!checkcardno(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custBirthday']:visible").each(function () {
        if (!checkBirth(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custPassport']:visible").each(function () {
        if (!checkPassport(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custPassportExpire']:visible").each(function () {
        if (!checkValidTo(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custPassportCityName']:visible").each(function () {
        if (!checkIssuePlace(this)) {
            $(this).focus();
            flag = false;
        }
    });
    if (!flag) {
        return false;
    }
    showLoader($("#frmOrder").find("input[type=submit]")[0]);
    return true;
}

function validateSubmit()
{
    flag = true;
    if (!checkEmail())
    {
        $("#contactEmail").focus();
        flag= false;
    }
    if (!checkCell()) {
        $("#contactCell").focus();
        flag= false;
    }
    if (!checkCName(document.getElementById("contactName")))
    {
        document.getElementById("contactName").focus();
        flag = false;
    }
    $("input[name='custName']").each(function () {
        if (!checkCName(this))
        {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custCertificate']").each(function () {
        if (!checkcardno(this))
        {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custBirthday']:visible").each(function () {
        if (!checkBirth(this))
        {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custPassport']:visible").each(function () {
        if (!checkPassport(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custPassportExpire']:visible").each(function () {
        if (!checkValidTo(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='custPassportCityName']:visible").each(function () {
        if (!checkIssuePlace(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='invoice']:visible").each(function () {
        if (!checkIsInvoice(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("select[name='invoiceType']:visible").each(function () {
        if (!checkIsinvoiceType(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='inaddress']:visible").each(function () {
        if (!checkIsInaddress(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='incode']:visible").each(function () {
        if (!checkIsIncode(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='inreceiver']:visible").each(function () {
        if (!checkIsInreceiver(this)) {
            $(this).focus();
            flag = false;
        }
    });
    $("input[name='inphone']:visible").each(function () {
        if (!checkIsInphone(this)) {
            $(this).focus();
            flag = false;
        }
    });
    if (!flag)
    {
        return false;
    }
    showLoader($("#frmOrder").find("input[type=submit]")[0]);
    return true;
}
//移除验证文本div的class属性
function removeDivClass(id) {
    $("#div" + id).removeClass("ui-form-item-finish");
    $("#div" + id).removeClass("ui-form-item-error");
    $("#sp" + id).html("");
}
function blurShow(obj) {
    obj.val(obj.attr("def"));
    obj.css("color", "#888");
}
//统一验证函数
function CheckRegExp(pattern, value) {
    var reg = new RegExp(pattern);
    //alert(reg);
    return reg.exec(value) != null ? true : false;
}
//汉字名字
function checkname(x, y, checkType) {
    var sender = $("#txtTravellerName" + x);
    var pattern = /^[\u0391-\uFFE5]+$/;
    var re = /^[a-zA-Z\d\u4e00-\u9fa5]+$/;
    if (sender.length == 1) {
        removeDivClass("TravellerName" + x);
        if (!sender.val()) {
            if (checkType == 2) {
                $("#spTravellerName" + x).html("请输入中文姓名");
                $("#divTravellerName" + x).addClass("ui-form-item-error");
                $("#divEnglishName" + x).addClass("hidden");
                return false;
            }
            else {
                blurShow(sender);
            }
        }
        else if ((!CheckRegExp(pattern, sender.val())) || (!re.test(sender.val()))) {
            $("#spTravellerName" + x).html("请输入中文姓名");
            $("#divTravellerName" + x).addClass("ui-form-item-error");
            $("#divEnglishName" + x).addClass("hidden");
            return false;
        }
        else if (sender.val().length > 8 || sender.val().length <= 1) {
            $("#spTravellerName" + x).html("请正确输入中文姓名");
            $("#divTravellerName" + x).addClass("ui-form-item-error");
            $("#divEnglishName" + x).addClass("hidden");
            return false;
        }
    }
    if (!sender.val()) {
        return false;
    }
    $("#divTravellerName" + x).addClass("ui-form-item-finish");
    if (y == 1) {
        $.get(PageInit.AjaxUrl + "SparkleOrder/GetPinyin", { "name": sender.val() },
            function (data) {
                $("#divEnglishName" + x).removeClass("hidden");
                $("#aEnglishNameModify" + x).removeClass("hidden");
                if (data.split(' ')[0] != "") {
                    $("#iptxing" + x).val(data.split(' ')[0]);
                }
                if (data.split(' ')[1] != "") {
                    $("#iptming" + x).val(data.split(' ')[1]);
                }
                if ($("#iptxing" + x).val().length > 50 || $("#iptming" + x).val().length > 50) {
                    $("#spEnglishName" + x).html("长度需小于50");
                    $("#divEnglishName" + x).addClass("ui-form-item-error");
                    return false;
                }
                else {
                    $("#spEnglishNameShow" + x).html(data);
                    $("#spEnglishNameShow" + x).removeClass("hidden");
                    $("#iptxing" + x).addClass("hidden");
                    $("#iptming" + x).addClass("hidden");
                    $("#spEnglishName" + x).html("请您核对拼音无误");
                }
            });
    }
    return true;
}

//拼音
function checkpinyin(x) {
    var senderX = $("#iptxing" + x);
    var senderM = $("#iptming" + x);
    var pattern = /^[a-zA-Z]+$/;
    var reg = /[\s]/g;
    if (senderX.length == 1 && senderM.length == 1) {
        if (senderX.val().replace(reg, "") == "") {
            $("#spEnglishNameShow" + x).addClass("hidden");
            $("#aEnglishNameModify" + x).addClass("hidden");
            senderX.removeClass("hidden");
            senderM.removeClass("hidden");
            senderX.focus();
            $("#spEnglishName" + x).html("拼音输入有误");
            return false;
        }
        if (senderM.val().replace(reg, "") == "") {
            $("#spEnglishNameShow" + x).addClass("hidden");
            $("#aEnglishNameModify" + x).addClass("hidden");
            senderX.removeClass("hidden");
            senderM.removeClass("hidden");
            senderM.focus();
            $("#spEnglishName" + x).html("拼音输入有误");
            return false;
        }
        if (!GLOBAL.Lang.fucIptchk(senderX.val())) {
            $("#spEnglishNameShow" + x).addClass("hidden");
            $("#aEnglishNameModify" + x).addClass("hidden");
            senderX.removeClass("hidden");
            senderM.removeClass("hidden");
            senderX.focus();
            $("#spEnglishName" + x).html("拼音输入有误");
            return false;
        }
        else if (!GLOBAL.Lang.fucIptchk(senderM.val())) {
            $("#spEnglishNameShow" + x).addClass("hidden");
            $("#aEnglishNameModify" + x).addClass("hidden");
            senderX.removeClass("hidden");
            senderM.removeClass("hidden");
            senderM.focus(x);
            $("#spEnglishName" + x).html("拼音输入有误");
            return false;
        }
        else if (senderX.val().length > 50 || senderM.val().length > 50) {
            $("#spEnglishNameShow" + x).addClass("hidden");
            $("#aEnglishNameModify" + x).addClass("hidden");
            senderX.removeClass("hidden");
            senderM.removeClass("hidden");
            senderX.focus();
            $("#spEnglishName" + x).html("拼音输入有误");
            return false;
        }
    }
    $("#spEnglishName" + x).html("请您核对拼音无误");
    return true;
}


//选择区域
function showGroupPassportPlace(id, x) {
    $("#tabs2-a" + x).attr("style", "display:none");
    $("#tabs2-b" + x).attr("style", "display:none");
    $("#tabs2-c" + x).attr("style", "display:none");
    $("#tabs2-d" + x).attr("style", "display:none");

    $("#liGroupPassportPlace-a" + x).removeClass("ui-tabs-active");
    $("#liGroupPassportPlace-b" + x).removeClass("ui-tabs-active");
    $("#liGroupPassportPlace-c" + x).removeClass("ui-tabs-active");
    $("#liGroupPassportPlace-d" + x).removeClass("ui-tabs-active");

    $("#liGroupPassportPlace-" + id + x).addClass("ui-tabs-active");
    $("#tabs2-" + id + x).attr("style", "display:block")
}

//选择签发地
function showPassportPlace(id, x, name) {
    removeDivClass("passportplace" + x);
    $("#txtpassportplace" + x).val(name);
    $("#hidpassportplace" + x).val(id);
    $("#tabs2" + x).css("display", "none");
    //$("#divpassportplace" + x).addClass("ui-form-item-finish");
}
//移除验证文本div的class属性
function removeDivClass(id) {
    $("#div" + id).removeClass("ui-form-item-finish");
    $("#div" + id).removeClass("ui-form-item-error");
    $("#sp" + id).html("");
}
function modifyTraveler(obj) {
    var p = $(obj).parents(".shenCYLeft");
    p.next(".shenCYRight").show();
    p.hide();
}
function unmodifyTraveler(obj)
{
    var p = $(obj).parents(".shenCYRight");
    p.prev(".shenCYLeft").show();
    p.hide();
}
function showAddNewDiv(obj)
{
    $(obj).prev("#newGuest").show();
    $(obj).hide();
}
function hideAddNewDiv(obj)
{
    var $parent = $(obj).parents("#newGuest");
    $(".add-new-guest").show();
    $parent.hide();
    $parent.find(".msgerror").hide();
    $parent.find("input[type=text]").val("");
    $parent.find("select").each(function () {
        this.options[0].selected = true;
    });
    $parent.find("input[name=rdoSex]:eq(0)").prop("checked",true);
}
function checkGuestSubmition(obj) {
    var frm = $(obj);
    var result = true;
    
    if (!checkVoucherNo(frm.find("input[name=txtVoucherNo]")[0])) {
        result = false;
        frm.find("input[name=txtVoucherNo]").focus();
    }
    if (!checkMobileNum(frm.find("input[name='txtMobile']")[0]))
    {
        result = false;
        frm.find("input[name='txtMobile']").focus();
    }

    if (!checkLName(frm.find("input[name='txtLName']")[0]))
    {
        result = false;
        frm.find("input[name='txtLName']").focus();
    }

    if (!checkFName(frm.find("input[name='txtFName']")[0]))
    {
        result = false;
        frm.find("input[name='txtFName']").focus();
    }
    if (!checkTName(frm.find("input[name='txtName']")[0])) {
        result = false;
        frm.find("input[name='txtName']").focus();
    }
    return result;
}
function checkMobileNum(obj)
{
    var $obj= $(obj);
    var frm = $obj.parents('form[name=frmGuest]')
    var reg = /^((\+86)|(86))?(1)\d{10}$/;
    if (reg.test($obj.val())) {
        frm.find(".msgcell").hide();
        return true;
    }
    else {
        frm.find(".msgcell").show();
        return false;
    }
}
function checkLName(obj)
{
    var $obj = $(obj);
    var frm = $obj.parents('form[name=frmGuest]')
    var regPinyin = /^[a-zA-Z]+$/;
    if (regPinyin.test($obj.val())) {
        frm.find(".msglname").hide();
        return true;
    }
    else {
        frm.find(".msglname").show();
        return false;
    }
}
function checkFName(obj)
{
    var $obj = $(obj);
    var frm = $obj.parents('form[name=frmGuest]')
    var regPinyin = /^[a-zA-Z]+$/;
    if (regPinyin.test($obj.val())) {
        frm.find(".msgfname").hide();
        return true;
    }
    else {
        frm.find(".msgfname").show();
        return false;
    }
}
function checkVoucherNo(obj) {
    var $obj = $(obj);
    var frm = $obj.parents('form[name=frmGuest]');
    if (!$obj.val())
    {
        frm.find(".msgidcard").show();
        return false;
    }
    if (frm.find("select[name=selVoucherType]").val() == 1)
    {
        if ($obj.val().length != 18 || parseInt($obj.val().substring(6, 10), 10) < 1930 ||
                    parseInt($obj.val().substring(6, 10), 10) > 2020 || parseInt($obj.val().substring(10, 12), 10) > 12 || parseInt($obj.val().substring(10, 12), 10) < 1
                     || parseInt($obj.val().substring(12, 14), 10) < 1 || parseInt($obj.val().substring(12, 14), 10) > 31 || !checkIdCard($obj.val())) {
            frm.find(".msgidcard").show();
            return false;
        }
    }
    frm.find(".msgidcard").hide();
    return true;
}

function checkTName(obj) {
    var $obj = $(obj);
    var frm = $obj.parents('form[name=frmGuest]');
    var pattern = /^[\u0391-\uFFE5]+$/;
    var re = /^[a-zA-Z\d\u4e00-\u9fa5]+$/;
    if ((!pattern.test($obj.val())) || (!re.test($obj.val()))) {
        /*
        $("#spTravellerName" + x).html("请输入中文姓名");
        $("#divTravellerName" + x).addClass("ui-form-item-error");
        $("#divEnglishName" + x).addClass("hidden");
        */
        frm.find(".msgname").show();
        return false;
        
    }
    else if ($obj.val().length > 8 || $obj.val().length <= 1) {
        /*
         $("#spTravellerName" + x).html("请正确输入中文姓名");
         $("#divTravellerName" + x).addClass("ui-form-item-error");
         $("#divEnglishName" + x).addClass("hidden");
        */
        frm.find(".msgname").show();
        return false;
    }
    frm.find(".msgname").hide();
    return true;
   
}

function showLoader(obj)
{
    var loader = $(obj).siblings('.loaderbtn');
    if (loader.length == 0) {
        var tempLoader = $("body .loaderbtn:eq(0)").clone();
        $(obj).parent().append(tempLoader);
    }
    $(obj).siblings('.loaderbtn').css("line-height", $(obj).siblings('.loaderbtn').height()+"px");
    $(obj).siblings('.loaderbtn').fadeIn(300);
}


function editContactInfo(obj) {
    $(".contacteditor").show();
    $(".contactinfo").hide();
    $(".contactbutton").hide();
    //$(".cancelcontactbutton").show();
}
function cancelContactInfo() {
    $(".contacteditor").hide();
    $(".contactinfo").show();
    $(".contactbutton").show();
    //$(".cancelcontactbutton").hide();
}
function saveContactInfo() {
    var flag = true;
    if (!checkEmail()) {
        flag = false;
    }
    if (!checkCell()) {
        flag = false;
    }
    if (!checkCName(document.getElementById("contactName"))) {
        flag = false;
    }
    if (!flag) {
        return false;
    }
    $(".contact-email").text($("#contactEmail").val());
    $(".contact-cell").text($("#contactCell").val());
    $(".contact-namer").text($("#contactName").val());
    cancelContactInfo();
}

function editTravelerInfo(obj) {
    $(".travelereditor").show();
    $(".travelerinfo").hide();
    $(".travelerbutton").hide();
    //$(".canceltravelerbutton").show();
}
function cancelTravelerInfo() {
    $(".travelereditor").hide();
    $(".travelerinfo").show();
    $(".travelerbutton").show();
    //$(".canceltravelerbutton").hide();
}
function saveTravelerInfo() {
    var flag = true;
    $("input[name='custName']").each(function () {
        if (!checkCName(this)) {
            flag = false;
        }
    });
    $("input[name='custCertificate']").each(function () {
        if (!checkcardno(this)) {
            flag = false;
        }
    });
    $("input[name='custBirthday']:visible").each(function () {
        if (!checkBirth(this)) {
            flag = false;
        }
    });
    $("input[name='custPassport']:visible").each(function () {
        if (!checkPassport(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    $("input[name='custPassportExpire']:visible").each(function () {
        if (!checkValidTo(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    $("input[name='custPassportCityName']:visible").each(function () {
        if (!checkIssuePlace(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    $("input[name='invoice']:visible").each(function () {
        if (!checkIsInvoice(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    $("select[name='invoiceType']:visible").each(function () {
        if (!checkIsinvoiceType(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    $("input[name='inaddress']:visible").each(function () {
        if (!checkIsInaddress(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    $("input[name='incode']:visible").each(function () {
        if (!checkIsIncode(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    $("input[name='inreceiver']:visible").each(function () {
        if (!checkIsInreceiver(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    $("input[name='inphone']:visible").each(function () {
        if (!checkIsInphone(this)) {
            $(this).prev().focus();
            flag = false;
        }
    });
    if (!flag) {
        return false;
    }


    $(".custContainer").each(function (index) {
        var $touredit = $(this);
        var $tourinfo = $(".travelerinfo .one").eq(index);
        $tourinfo.find(".stravelername").text($touredit.find("input[name=custName]").val());
        $tourinfo.find(".stravelercardtype").text($touredit.find("select[name=custCertifiType] option:selected").text().trim());
        $tourinfo.find(".stravelercardno").text($touredit.find("input[name=custCertificate]").val());
        $tourinfo.find(".stravelerbirthday").text($touredit.find("input[name=custBirthday]").val());
        $tourinfo.find(".stravelersex").text($touredit.find("input[name^=rdoSex]:checked").siblings("span").text());
        if ($touredit.find("input[name=hidInputCustomer]").val() == "true") {
            $tourinfo.find(".sprovide").text("已提供");
        }
        else {
            $tourinfo.find(".sprovide").text("稍后提供");
        }

    });
    cancelTravelerInfo();
}